from datetime import timedelta

from flask import Flask, jsonify, render_template
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate

from api.apibase import api
from models import db
from config import Config
from flask_cors import CORS

app = Flask(__name__)
app.config.from_object(Config)
app.config['JWT_SECRET_KEY'] = 'sk-dksfjlasfdjflsjdfbjbur'
# 设置token的过期时间
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(weeks=3)
db.init_app(app)
migrate = Migrate(app, db)

# 创建蓝图
app.register_blueprint(api, url_prefix='/api')

jwt = JWTManager(app)

CORS(app)


@app.route('/', methods=['GET', 'POST'])
def hello_world():
    return jsonify({'status': 'base is ok'})


if __name__ == '__main__':
    app.run(debug=True)
